<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>恒铸智能柜管理平台</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/resources/layui/css/layui.css"
	media="all" />
<script type="text/javascript"
	src="${pageContext.request.contextPath}/resources/layui/layui.js"></script>
</head>
<style>
.laytable-cell-1-url {
	width: 340px !important;
}
</style>
<body class="childrenBody">
	<form class="layui-form">
		<blockquote class="layui-elem-quote admin_search">
			<div>
				<a type="button" class="layui-btn" id="uploadBtn">上传</a>
			</div>
		</blockquote>
		<table id="adList" lay-filter="adList"></table>

		<!--操作-->
		<script type="text/html" id="publish">
		<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
	</script>
	</form>
	<script>
	layui.use(['form','layer','laydate','table','laytpl','upload'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        laydate = layui.laydate,
        laytpl = layui.laytpl,
        table = layui.table;
    	upload = layui.upload;
var domainUrl="12312";
    //新闻列表
    var tableIns = table.render({
        elem: '#adList',
        url : '/myApk/getApkList',
        page : true,
        height : "full-125",
        limit : 20,
        limits : [10,15,20,25],
        id : "adListTable",
        cols : [[
            {field: 'packageName', title: 'packageName',  align:'center'},
            {field: 'versionName', title: 'versionName', align:'center'},
            {field: 'versionCode', title: 'versionCode', align:'center'},
            {field: 'url', title: 'url', align:'center',templet:function(f){
            	var urlstr=f.url;
            	return '<a href="'+urlstr+'" target="target" >'+urlstr+'</a>'
            } },
            {field: 'createTime', title: '上传时间', align:'center'},
            {title: '操作', width:90, templet:'#publish',fixed:"right",align:"center",width :150}
        ]]
    });

    
    
    //列表操作
    table.on('tool(adList)', function(obj){
        var layEvent = obj.event,
            data = obj.data;
       if(layEvent === 'del'){ //删除
            layer.confirm('确定删除此APK？',{icon:3, title:'提示信息'},function(index){
            	$.post("/myApk/deleteApk?id="+data.id,function(rest){
            		layer.msg(rest.message);
            	})
                tableIns.reload();
                layer.close(index);
            });
        }
    });
    
    
    var uploadInst = upload.render({
	    elem: '#uploadBtn' //绑定元素
	    ,url: '/myApk/uploadFile' //上传接口
    	,accept: 'file'
    	,before:function(obj){
    		$("#uploadBtn").html("上传中...");
    		layer.load(2);
		  }
    	,done: function(res){
    		layer.closeAll('loading');
    		var code=res.code;
    		if(code==100){
    			$("#uploadBtn").html("上传");
    			key = res.fileName;
    			flag=2;
    			 tableIns.reload();
    			layer.alert('上传完成', {icon: 6});
    		}else{
    			layer.alert('上传失败', {icon: 5});
    		}
	      //上传完毕回调
	    }
	    ,error: function(){
	    	$("#uploadBtn").html("上传");
	    	layer.closeAll('loading');
	      //请求异常回调
	    	layer.alert('上传失败', {icon: 5});
	    }
  }); 

})
</script>
</body>
</html>